package com.test.demo.controller;
/**
 * 王宇controller层代码
 * */

import com.test.demo.model.Role;
import com.test.demo.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController(value = "/Role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @RequestMapping(value = "/getString")
    public String getStr(String str) {
        return "你输入的名字叫：" + str;
    }

    @CrossOrigin
    @RequestMapping(value = "/getOne")
    public Role getOne(Integer rid) {
        return roleService.selectByPrimaryKey(rid);
    }

    @CrossOrigin//解决跨域问题
    @RequestMapping(value = "getIsBegin")
    public List<Role> getIsBegin(){
        System.out.println("调用角色全部类型的接口");
        List<Role> listRole=roleService.getIsBegin();
        return listRole;
    }

    @CrossOrigin
    @RequestMapping(value = "getAll" )
    public List<Role> getAll(){
        System.out.println("调用角色全部信息的方法");
       return roleService.getAll();
    }
    @CrossOrigin
    @RequestMapping(value = "delRole",method = RequestMethod.GET)
    public int delRole(Integer rid){
        return roleService.delRole(rid);
    }

    @CrossOrigin
    @RequestMapping(value = "addRole",method = RequestMethod.PUT)
    public int addRole(@RequestBody Role rolemodel){
        //判断传参是否为空
        if (rolemodel!=null){

        }else {

        }
        return roleService.insertRole(rolemodel);
    }
    @CrossOrigin
    @RequestMapping(value = "updateRole",method = RequestMethod.PUT)
    public int updateRole(@RequestBody Role rolemodel){
        return roleService.updateRole(rolemodel);
    }
}

